package com.tanhua.admin.controller;

import com.tanhua.admin.service.ManageService;
import com.tanhua.model.domain.UserInfo;
import com.tanhua.model.vo.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/manage")
public class ManageController {


    @Autowired
    private ManageService manageService;

    @GetMapping("/users")
    public ResponseEntity findAll(@RequestParam(defaultValue = "1") Integer page,
                                  @RequestParam(defaultValue = "10") Integer pagesize) {
        PageResult pr = manageService.findAll(page, pagesize);
        return ResponseEntity.ok(pr);
    }

    @GetMapping("/users/{userId}")
    public ResponseEntity findByUserInfo(@PathVariable("userId") Long userId) {
        UserInfo userInfo = manageService.findByUserInfo(userId);
        return ResponseEntity.ok(userInfo);
    }


    @GetMapping("/videos")
    public ResponseEntity videos(@RequestParam(defaultValue = "1") Integer page,
                                 @RequestParam(defaultValue = "10") Integer pagesize,
                                 Long uid) {
        PageResult pr = manageService.findByUserVideos(page, pagesize, uid);
        return ResponseEntity.ok(pr);

    }

    @GetMapping("/messages/{id}")
    public ResponseEntity movements(@RequestParam(defaultValue = "1") Integer page,
                                    @RequestParam(defaultValue = "10") Integer pagesize,
                                    Long uid, Integer state) {
        PageResult pr = manageService.findAllMovements(page, pagesize, uid, state);
        return ResponseEntity.ok(pr);
    }

    //冻结用户
    @PostMapping("/users/freeze")
    public ResponseEntity freezeUser(@RequestBody Map map) {
        Map mp =manageService.freezeUser(map);
        return ResponseEntity.ok(mp);
    }

    //用户解冻
    @PostMapping("/users/unfreeze")
    public ResponseEntity unfreeze(@RequestBody  Map params) {
        Map map =  manageService.userUnfreeze(params);
        return ResponseEntity.ok(map);
    }
}
